package com.zhongkai.service.impl;

import com.mysql.jdbc.StringUtils;
import com.zhongkai.app.service.IBaseDao;
import com.zhongkai.app.service.RoleControlService;
import com.zhongkai.model.utils.ZhongkaiResult;
import com.zhongkai.model3.SetRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class RoleControlServiceImpl implements RoleControlService {


    @Autowired
    private IBaseDao iBaseDao;


/*    @Autowired
    private JedisClient jedisClient;*/

    @Override
    public ZhongkaiResult role_add(String name) {


        if (StringUtils.isNullOrEmpty(name)) {
            return ZhongkaiResult.build(400, "参数不完整");
        }

        try {


            SetRole setRole = (SetRole) iBaseDao.get("from SetRole rl where rl.name='" + name + "'");

            if (setRole != null) {
                return ZhongkaiResult.build(400, "此角色已存在");
            }

            setRole = new SetRole();

            setRole.setName(name);
            setRole.setRemove("1");
            iBaseDao.save(setRole);
            return ZhongkaiResult.ok();

        } catch (Exception e) {
            e.printStackTrace();
            return ZhongkaiResult.build(400, "添加失败");
        }
    }
}
